//modifief for http://www.Knowhowto.tk 
document.getElementById('blog-pager').style.display='block';
var canvas='';
function writescript(callback){document.write('\<script src="/feeds/posts/summary?alt=json-in-script&callback='+callback+'&start-index=' + startindex + '&max-results=100" \>\<\/script\>');}
function writelabelscript(callback){document.write('\<script src="/feeds/posts/summary/-/' + label + '?alt=json-in-script&callback='+callback+'&start-index=' + startindex + '&max-results=100" \>\<\/script\>');}
var url = location.href,total;
var already=new Boolean(false);
var timestamps = new Array();
if (url.indexOf("/search/label/") != -1)
 {
    if (url.indexOf("?updated-max") != -1) {var label = url.substring(url.indexOf("/search/label/") + 14, url.indexOf("?updated-max"))} else {var label = url.substring(url.indexOf("/search/label/") + 14, url.indexOf("?&max"));}
 }

if (url.indexOf("#Page") != -1)  {var currentpagenum = parseInt(url.substring(url.indexOf("#Page") + 5, url.length));}    else var currentpagenum=1;
var startindex=(currentpagenum-displayPageNum-1>0)?((currentpagenum-displayPageNum-2)*pageCount + 1) : 1;
var total=(2*displayPageNum+1)*pageCount;

if (url.indexOf("?q=") == -1&& url.indexOf(".html") == -1) 
{   
    if (url.indexOf("/search/label/") == -1) {var islabel=new Boolean(false);do {writescript("buildtimestamps");startindex+=100;}while(total>startindex)}
    else {var islabel=new Boolean(true);do {writelabelscript("buildtimestamps");startindex+=100;}while(total>startindex)}
    document.write('\<script type="text/javascript"\>printnav();\<\/script\>');
    
}

function buildtimestamps(json)
{
if(already==false)
{
total=parseInt(json.feed.openSearch$totalResults.$t);
}
init =pageCount-1;
for (var i = init;post = json.feed.entry[i]; i+=pageCount) 
timestamps[timestamps.length] = encodeURIComponent(post.published.$t.substring(0, 19) + post.published.$t.substring(23, 29));

}

function printlast(json)
{
var tstamp=encodeURIComponent(json.feed.entry[0].published.$t.substring(0, 19) + json.feed.entry[0].published.$t.substring(23, 29));
if(islabel==false){link= 'search?updated-max=' + tstamp + '&max-results=' + pageCount + '#Page'+maxpages;} else link=  '/search/label/' + label + '?updated-max=' + tstamp + '&max-results=' + pageCount + '#Page'+maxpages;
document.getElementById('showlastpage').innerHTML='<a href=\"' + link + '\">' + maxpages + '</a>';
}

function printnav()
{
maxpages=Math.ceil(total/pageCount);
canvas=canvas+'<span class="totalpages">Pages (' + maxpages + ')</span>';
var end=((currentpagenum+displayPageNum)<maxpages)?currentpagenum+displayPageNum:maxpages;
var start=((currentpagenum-displayPageNum)>1)?currentpagenum-displayPageNum:1;

if(currentpagenum>1) 
{
if(islabel==false) {if(currentpagenum==2) link='/'; else link= 'search?updated-max=' + timestamps[(start==1)?currentpagenum-start-2:currentpagenum-start-1] + '&max-results=' + pageCount + '#Page'+(currentpagenum-1);}
else  if(currentpagenum==2) link='/search/label/' + label + '?&max-results=' + pageCount;  else link=  '/search/label/' + label +'?updated-max=' + timestamps[(start==1)?currentpagenum-start-2:currentpagenum-start-1] + '&max-results=' + pageCount + '#Page'+(currentpagenum-1);

canvas=canvas+' <span class="showpage"><a href="' + link + '">Previous</a></span>';
}

if(start!=1) {if(islabel==true) canvas=canvas+'<span class="showpageNum"><a href=\"/search/label/' + label + '&max-results=' + pageCount+'\">1</a></span>'; else canvas=canvas+'<span class="showpageNum"><a href=\"/\">1</a></span>';canvas=canvas+'...'; }
for(var j=start;j<=end;j++)
{
if(islabel==true)
{
if(j==1) link='/search/label/' + label + '?&max-results=' + pageCount; else  link=  '/search/label/' + label + '?updated-max=' + timestamps[(start==1)?j-start-1:j-start] + '&max-results=' + pageCount + '#Page'+j;
if(j==currentpagenum) canvas=canvas+'<span class="showpagePoint">' + j + '</span>'; else canvas=canvas+'<span class="showpageNum"><a href=\"' + link + '\">' + j + '</a></span>';
}
else 
{
if(j==1) link='/';else link= 'search?updated-max=' + timestamps[(start==1)?j-start-1:j-start] + '&max-results=' + pageCount + '#Page'+j;
if(j==currentpagenum) canvas=canvas+'<span class="showpagePoint">' + j + '</span>'; else canvas=canvas+'<span class="showpageNum"><a  href=\"' + link + '\">' + j + '</a></span>';
}
}
if(end!=maxpages) {canvas=canvas+' .. '+'<span id="showlastpage" class="showpage"></span>';startindex=Math.floor((total-1)/pageCount)*pageCount;if(islabel==true) writelabelscript("printlast");else writescript("printlast");}
if(currentpagenum<maxpages) 
{
if(islabel==false) link= 'search?updated-max=' + timestamps[(start==1)?currentpagenum-start:currentpagenum+1-start] + '&max-results=' + pageCount + '#Page'+(currentpagenum+1);
else link= '/search/label/' + label +'?updated-max=' + timestamps[(start==1)?currentpagenum-start:currentpagenum+1-start] + '&max-results=' + pageCount + '#Page'+(currentpagenum+1);
canvas=canvas+' <span class="showpage"><a href="' + link + '">Next</a></span>';
}
document.getElementById('blog-pager').innerHTML=canvas;
}